{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "########################## 原理说明 #######################\n",
    "# 1）在手机端（目前仅测过android手机）里装向日葵服务端\n",
    "#    作者测试的手机是：美图M8\n",
    "#    安装注意事项：在“授权管理”里打开手机的root \n",
    "#                  如果在设置里没有，那么就是在桌面的“安全中心”里有“授权管理”这个选项 \n",
    "# 2）然后电脑端的向日葵客户远程控制手机里的向日葵，此时手机里的显示会重定向到电脑\n",
    "# 3）使用我们的脚本模拟人操作tikop的动作，自动操作手机里的tiktop,达到养号的目的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 作者：chenyujing（微信号:15280006510  QQ: 594462206）,欢迎交流\n",
    "################ \n",
    "##  使用者一定要准备的工作：\n",
    "##### 1.电脑端的向日葵客户端能远程控制手机端,此时电脑端可以看到手机屏幕且能远程操作\n",
    "##### 2.配置“返回按钮的位置”、 “TikTok视频滑动位置”、“TikTok的评论键位置”、“Tiktok的主页键位置”、“Tiktok的点赞键位置”\n",
    "##### 3. 配置完时间后，运行此脚本：Cell -> Run All \n",
    "#        运行后，把浏览器最小化就好（切记，不要关闭这个浏览器页面”；\n",
    "#        也不要关闭“管理员：Anaconda Prompt”这个命令窗口）\n",
    "#     4. 注意：如果脚本一旦运行起来，想修改配置数据，需要先将程序停止，然后再启动脚本 \n",
    "#        停止脚本的方法：Kernel -> Restart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#################### 要配置的参数   ################################\n",
    "LEI_DIAN_FW_TOP_BANNER = 33\n",
    "LEI_DIAN_FW_RIGHT_BANNER = 40\n",
    "# TikTok视频滑动\n",
    "DOU_YIN_SHI_PING_SLID_TOP = 130\n",
    "# 按下TikTok的评论键\n",
    "PING_LUN_X = 142\n",
    "PING_LUN_Y = 380\n",
    "# 按下Tiktok的主页键\n",
    "ZHU_YE_X = 142\n",
    "ZHU_YE_Y = 250\n",
    "# 按下Tiktok的点赞键\n",
    "DIAN_ZAN_X = 142\n",
    "#       无直播\n",
    "#DIAN_ZAN_Y = 310\n",
    "#       有直播\n",
    "DIAN_ZAN_Y = 320\n",
    "# 返回键 \n",
    "FAN_HUI_X = 140\n",
    "FAN_HUI_Y = 700\n",
    "# 评论滚动的开始位置 \n",
    "PING_LUN_SLIDE_Y = 180\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'scope': 'brain_ocr_meter brain_doc_analysis brain_ocr_webimage_loc vis-ocr_机动车购车发票识别 brain_ocr_vehicle_invoice brain_formula vis-ocr_行程单识别 brain_ocr_air_ticket brain_qrcode brain_ocr_business_card vis-ocr_保单识别 brain_ocr_insurance_doc vis-ocr_vis-classify_birth_certificate vis-ocr_台湾通行证 vis-ocr_港澳通行证 brain_ocr_birth_certificate brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_solution_iocr vis-ocr_household_register vis-ocr_机动车检验合格证识别 brain_ocr_household_register brain_ocr_vehicle_certificate brain_ocr_passport vis-ocr_定额发票识别 brain_ocr_quota_invoice vis-ocr_车辆vin码识别 brain_ocr_vin brain_ocr_train_ticket brain_ocr_taxi_receipt brain_numbers brain_ocr_vat_invoice brain_ocr_handwriting public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic brain_ocr_general_enhanced vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'refresh_token': '25.7707c701d9a108e28030b9a29e6af68c.315360000.1986304723.282335-10955179', 'session_secret': '23c7a8c3b78fdb2710ec382d8640cbb6', 'expires_in': 2592000, 'access_token': '24.032b9fda0c4388e49e6666a709e8504b.2592000.1673536723.282335-10955179', 'session_key': '9mzdCytPIobkgIZef4jhrpQqMOEgkY5XRZ7UGQ4qAbApSdYhNK1eZDc7pmpHZ185+xWinCb/8/89ncYYGOikQEdITlMZmg=='}\n",
      "16000\n"
     ]
    }
   ],
   "source": [
    "import pyautogui\n",
    "import time \n",
    "import shutil \n",
    "import os\n",
    "import pyperclip\n",
    "import win32gui\n",
    "from hashlib import md5\n",
    "import stat\n",
    "from PIL import Image\n",
    "import time\n",
    "from random import sample\n",
    "import test_baidu_ocr  \n",
    "import random\n",
    "\n",
    "#\"\"\"\n",
    "LEI_DIAN_TITLE_BEGIN_LIST = [\"Xiaomi\", \"Meitu\"]\n",
    "#\"\"\"\n",
    "\n",
    "SCREENSHOT_SAVE_DIR = \"./screenshot_img\"\n",
    "if False == os.path.exists(SCREENSHOT_SAVE_DIR):\n",
    "    os.mkdir(SCREENSHOT_SAVE_DIR)\n",
    "LEI_DIAN_FW = None\n",
    "LEI_DIAN_FW_LEFT = 0\n",
    "LEI_DIAN_FW_RIGHT = 0\n",
    "LEI_DIAN_FW_TOP = 0\n",
    "LEI_DIAN_FW_BOTTOM = 0\n",
    "LEI_DIAN_FW_WIDTH = 0\n",
    "LEI_DIAN_FW_HEIGHT = 0\n",
    "# 远程控制的设备列表及对应的table信息\n",
    "DEVICE_LIST = []\n",
    "\n",
    "\n",
    "g_img_count = 0\n",
    "\n",
    "if True == os.path.exists(SCREENSHOT_SAVE_DIR):\n",
    "    # chenyj test\n",
    "    os.chmod(SCREENSHOT_SAVE_DIR, stat.S_IWUSR)\n",
    "    # chenyj test\n",
    "    #shutil.rmtree(SCREENSHOT_SAVE_DIR)\n",
    "    pass\n",
    "# chenyj test\n",
    "#os.mkdir(SCREENSHOT_SAVE_DIR)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def init():\n",
    "    global LEI_DIAN_FW_LEFT\n",
    "    global LEI_DIAN_FW_RIGHT\n",
    "    global LEI_DIAN_FW_TOP\n",
    "    global LEI_DIAN_FW_BOTTOM\n",
    "    global LEI_DIAN_FW_WIDTH\n",
    "    global LEI_DIAN_FW_HEIGHT\n",
    "    global  LEI_DIAN_FW\n",
    "    global DEVICE_LIST\n",
    "    fw_all = pyautogui.getAllWindows() # 返回屏幕上每个可见窗口的窗口对象列表。\n",
    "    b_found = False\n",
    "    for fw in fw_all:\n",
    "        for LEI_DIAN_TITLE_BEGIN in LEI_DIAN_TITLE_BEGIN_LIST:\n",
    "            if True == fw.title.startswith(LEI_DIAN_TITLE_BEGIN):\n",
    "                print(fw)\n",
    "                LEI_DIAN_FW_LEFT = fw.left\n",
    "                LEI_DIAN_FW_RIGHT = fw.right\n",
    "                LEI_DIAN_FW_TOP = fw.top\n",
    "                LEI_DIAN_FW_BOTTOM = fw.bottom\n",
    "                LEI_DIAN_FW_WIDTH = fw.right - fw.left\n",
    "                LEI_DIAN_FW_HEIGHT = fw.bottom - fw.top\n",
    "                LEI_DIAN_FW = fw\n",
    "                print(\"LEI_DIAN_FW_LEFT:{}\".format(LEI_DIAN_FW_LEFT))\n",
    "                print(\"LEI_DIAN_FW_TOP:{}\".format(LEI_DIAN_FW_TOP))\n",
    "                print(\"LEI_DIAN_FW_BOTTOM:{}\".format(LEI_DIAN_FW_BOTTOM))\n",
    "                b_found = True\n",
    "                \n",
    "                break \n",
    "    assert b_found == True, \"没有找到模拟器窗口\"\n",
    "    \n",
    "    # 找到所有设备的table的名字及位置\n",
    "    DEVICE_LIST = []\n",
    "    img_after_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"top_banner\" + \".png\"\n",
    "    pyautogui.screenshot(img_after_cut_path, region=(LEI_DIAN_FW_LEFT, LEI_DIAN_FW_TOP, LEI_DIAN_FW_WIDTH, LEI_DIAN_FW_TOP_BANNER))\n",
    "    print('Top banner保存到:{}'.format(img_after_cut_path))\n",
    "    ocr_result = test_baidu_ocr.get_ocr_result(img_after_cut_path)\n",
    "    print(\"OCR的结果：\", ocr_result)\n",
    "    for word_result in ocr_result[\"words_result\"]:\n",
    "        words = word_result[\"words\"]\n",
    "        location = word_result[\"location\"]\n",
    "        \n",
    "        words_list = [words]\n",
    "        location_list = [location]\n",
    "        #          '×Il Xiaomi MI2sC-3×l Xiaomi MI2sC-2×+'\n",
    "        #          'Il Xiaomi MI2sC-2×il Meitu MP1709×,l Xiaomi M2sC-4×Il Xiaomi MI2s'\n",
    "        # 将以上特例按×切开做特殊处理\n",
    "        words_ = words.replace(\"x\", \"×\")\n",
    "        words_ = words.strip(\"×\")\n",
    "        str_list = words_.split(\"×\")\n",
    "        str_list = [str for str in str_list if len(str) > 7]\n",
    "        if len(str_list) > 1:\n",
    "            \n",
    "            print(\"！！！远程设备tab特殊处理\")\n",
    "            words_list = []\n",
    "            location_list = []\n",
    "            for i, str in enumerate(str_list):\n",
    "                words1 = str\n",
    "                words_list.append(words1)\n",
    "                location1 = {\"left\":location[\"left\"] + int(location[\"width\"]/len(str_list))*i, \"top\":location[\"top\"], \"width\":int(location[\"width\"]/len(str_list)), \"height\":location[\"height\"]}\n",
    "                location_list.append(location1)\n",
    "                \n",
    "        for i, words in enumerate(words_list):\n",
    "            location = location_list[i]\n",
    "            for LEI_DIAN_TITLE_BEGIN in LEI_DIAN_TITLE_BEGIN_LIST:\n",
    "                if LEI_DIAN_TITLE_BEGIN  in words:\n",
    "                    x = LEI_DIAN_FW_LEFT + int(location[\"left\"] + location[\"width\"]/2)\n",
    "                    y = LEI_DIAN_FW_TOP + int(location[\"top\"] + location[\"height\"]/2)\n",
    "                    DEVICE_LIST.append({\"name\":words, \"click_loccation\":(x, y)})\n",
    "    # 确保找到远程设备\n",
    "    assert len(DEVICE_LIST) != 0, \"没有找到远程控制的设备\" \n",
    "    print('找到的远程设备有【{}】个:{}'.format(len(DEVICE_LIST), DEVICE_LIST))\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<Win32Window left=\"824\", top=\"1\", width=\"540\", height=\"728\", title=\"Meitu MP1709\">\n",
      "LEI_DIAN_FW_LEFT:824\n",
      "LEI_DIAN_FW_TOP:1\n",
      "LEI_DIAN_FW_BOTTOM:729\n",
      "Top banner保存到:./screenshot_img/top_banner.png\n",
      "OCR的结果： {'words_result_num': 2, 'words_result': [{'words': 'Meitu MP1709', 'location': {'height': 10, 'top': 10, 'width': 97, 'left': 8}}, {'words': '×+', 'location': {'height': 13, 'top': 10, 'width': 51, 'left': 189}}], 'log_id': 1602684458295895506}\n",
      "找到的远程设备有【1】个:[{'name': 'Meitu MP1709', 'click_loccation': (880, 16)}]\n"
     ]
    }
   ],
   "source": [
    "# 抖音测试\n",
    "\n",
    "# 初始化\n",
    "init()\n",
    "\n",
    "# 任务栏中的微信聊天图标\n",
    "#   要求打开“文件传输助手”，且放在任务栏图标从左往右的第二个\n",
    "WEI_XIN_ICON_X = 0 + 519\n",
    "WEI_XIN_ICON_Y = LEI_DIAN_FW_BOTTOM + 10\n",
    "#time.sleep(10)\n",
    "\n",
    "\n",
    "# 滚动的开始位置 \n",
    "#pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2, LEI_DIAN_FW_BOTTOM - 200,duration=1)\n",
    "#pyautogui.dragTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2,LEI_DIAN_FW_HEIGHT/2 - 100, duration=1)   \n",
    "\n",
    "# 进入个人主页面 \n",
    "#pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + ZHU_YE_X, LEI_DIAN_FW_TOP + ZHU_YE_Y,duration=0.5)\n",
    "#pyautogui.click() \n",
    "#time.sleep(2)    \n",
    "# 按下点赞键\n",
    "#pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + DIAN_ZAN_X, LEI_DIAN_FW_TOP + DIAN_ZAN_Y,duration=0.5)\n",
    "#pyautogui.click() \n",
    "#time.sleep(1)\n",
    "        \n",
    "# 按下抖音的评论键\n",
    "#pyautogui.moveTo((LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + PING_LUN_X), LEI_DIAN_FW_TOP + PING_LUN_Y,duration=0.5)\n",
    "#pyautogui.click()\n",
    "#time.sleep(3)\n",
    "\n",
    "# 评论滚动的开始位置 \n",
    "#pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2, LEI_DIAN_FW_BOTTOM - PING_LUN_SLIDE_Y,duration=1)\n",
    " \n",
    "    \n",
    "# 返回键（一定要的测试项）\n",
    "pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + FAN_HUI_X, LEI_DIAN_FW_TOP + FAN_HUI_Y,duration=0.5)\n",
    "#pyautogui.click()\n",
    "time.sleep(0.5)\n",
    "\n",
    "\n",
    "# 测试任务栏中的微信聊天图标（一定要的测试项）\n",
    "\"\"\"\n",
    "pyautogui.moveTo(WEI_XIN_ICON_X, WEI_XIN_ICON_Y,duration=0.5)\n",
    "pyautogui.click()\n",
    "time.sleep(1)\n",
    "pyperclip.copy(\"监控新作品脚本成功启动\")\n",
    "time.sleep(1)\n",
    "pyautogui.hotkey('Ctrl', 'v')\n",
    "time.sleep(0.5)\n",
    "pyautogui.press('enter') \n",
    "time.sleep(2)\n",
    "pyautogui.moveTo(WEI_XIN_ICON_X, WEI_XIN_ICON_Y,duration=0.5)\n",
    "pyautogui.click()\n",
    "time.sleep(1)\n",
    "\"\"\"\n",
    "\n",
    "# 远程设备table切换测试\n",
    "for device_info in DEVICE_LIST:\n",
    "    device_click_location = device_info[\"click_loccation\"]\n",
    "    pyautogui.moveTo(device_click_location[0], device_click_location[1],duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n# 获得excel临时文件的句柄\\nhandle = win32gui.FindWindow(None, LEI_DIAN_TITLE)\\n# 激活并显示窗口。\\n#win32gui.ShowWindow(handle, win32con.SW_RESTORE) \\nwin32gui.EnableWindow(handle, True)\\nwin32gui.SetForegroundWindow(handle)\\ntime.sleep(1)\\n'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "# 获得excel临时文件的句柄\n",
    "handle = win32gui.FindWindow(None, LEI_DIAN_TITLE)\n",
    "# 激活并显示窗口。\n",
    "#win32gui.ShowWindow(handle, win32con.SW_RESTORE) \n",
    "win32gui.EnableWindow(handle, True)\n",
    "win32gui.SetForegroundWindow(handle)\n",
    "time.sleep(1)\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def is_can_run():\n",
    "    \n",
    "    return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "########## GUI 控制功能\n",
    "# 控制鼠标键盘使用的模块为：pyautogui，这个模块操作起鼠标键盘的时候，非常的迅速，\n",
    "# 而且如果该模块控制了鼠标后，程序比较难关闭，这时我们有两个方法专门针对以上的情况\n",
    "# 自动 防故障功能\n",
    "#      默认这项功能为True, 这项功能意味着：当鼠标的指针在屏幕的最坐上方，程序会报错；目的是为了防止程序无法停止；\n",
    "pyautogui.FAILSAFE = True  \n",
    "\n",
    "# 停顿功能\n",
    "#     意味着所有pyautogui的指令都要暂停一秒；其他指令不会停顿；这样做，可以防止键盘鼠标操作太快；\n",
    "pyautogui.PAUSE = 0.2\n",
    "# 调用每个PyAutoGUI函数后，会有十分之一秒的延迟，使用户有时间将鼠标猛撞到角落以触发故障保险。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def pixel_equal(image1, image2, x, y):\n",
    "    \"\"\"\n",
    "    判断两个像素是否相同\n",
    "    :param image1: 图片1\n",
    "    :param image2: 图片2\n",
    "    :param x: 位置x\n",
    "    :param y: 位置y\n",
    "    :return: 像素是否相同\n",
    "    \"\"\"\n",
    "    # 取两个图片像素点\n",
    "    piex1 = image1.load()[x, y]\n",
    "    piex2 = image2.load()[x, y]\n",
    "    threshold = 10\n",
    "    # 比较每个像素点的RGB值是否在阈值范围内，若两张图片的RGB值都在某一阈值内，则我们认为它的像素点是一样的\n",
    "    if abs(piex1[0] - piex2[0]) < threshold and abs(piex1[1]- piex2[1]) < threshold and abs(piex1[2] - piex2[2]) < threshold:\n",
    "        return True\n",
    "    else:\n",
    "        return False\n",
    "\n",
    "def compare(image1, image2):\n",
    "    \"\"\"\n",
    "    进行比较\n",
    "    :param image1:图片1\n",
    "    :param image2: 图片2\n",
    "    :return:\n",
    "    \"\"\"\n",
    "    left = 80\t\t# 坐标起始位置\n",
    "    right_num = 0\t# 记录相同像素点个数\n",
    "    false_num = 0\t# 记录不同像素点个数\n",
    "    all_num = 0\t\t# 记录所有像素点个数\n",
    "    for i in range(left, image1.size[0]):\n",
    "        for j in range(image1.size[1]):\n",
    "            if pixel_equal(image1, image2, i, j):\n",
    "                right_num += 1\n",
    "            else:\n",
    "                false_num += 1\n",
    "            all_num += 1\n",
    "    same_rate = right_num / all_num\t\t# 相同像素点比例\n",
    "    nosame_rate = false_num / all_num\t# 不同像素点比例\n",
    "    #print(\"same_rate: \", same_rate)\n",
    "    #print(\"nosame_rate: \", nosame_rate)\n",
    "    \n",
    "    return same_rate\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 滚动评论且获得评论的文本，最后返回 \n",
    "def slide_ping_lun_then_get_and_wait_and_back():\n",
    "    # 保存截图\n",
    "    img_befor_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"slide_ping_lun_last\" + \".png\"\n",
    "    pyautogui.screenshot(img_befor_cut_path, region=(LEI_DIAN_FW_LEFT, LEI_DIAN_FW_TOP + LEI_DIAN_FW_TOP_BANNER, LEI_DIAN_FW_WIDTH - LEI_DIAN_FW_RIGHT_BANNER, LEI_DIAN_FW_HEIGHT - LEI_DIAN_FW_TOP_BANNER))\n",
    "    #print(\"截了一张图，保存到:{}\".format(img_befor_cut_path))\n",
    "    # 获得评论内容 \n",
    "    b_has_ping_lun, ping_lun_list = test_baidu_ocr.get_ping_lun_ocr_result(img_befor_cut_path)\n",
    "    if False == b_has_ping_lun:\n",
    "        return True, ping_lun_list\n",
    "    \n",
    "    # 滑动评论区\n",
    "    pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2, LEI_DIAN_FW_BOTTOM - PING_LUN_SLIDE_Y,duration=1)\n",
    "    pyautogui.dragTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2,LEI_DIAN_FW_HEIGHT/2 - 200, duration=1)  \n",
    "    # 保存截图\n",
    "    img_after_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"slide_ping_lun_now\" + \".png\"\n",
    "    pyautogui.screenshot(img_after_cut_path, region=(LEI_DIAN_FW_LEFT, LEI_DIAN_FW_TOP + LEI_DIAN_FW_TOP_BANNER, LEI_DIAN_FW_WIDTH - LEI_DIAN_FW_RIGHT_BANNER, LEI_DIAN_FW_HEIGHT - LEI_DIAN_FW_TOP_BANNER))\n",
    "    #print(\"截了一张图，保存到:{}\".format(img_after_cut_path))\n",
    "    \n",
    "    #  像素相似比例比较 \n",
    "    image_before = Image.open(img_befor_cut_path)\n",
    "    image_after = Image.open(img_after_cut_path)\n",
    "    same_rate = compare(image_before, image_after)\n",
    "    \n",
    "    # 比较方式二：md5比较 \n",
    "    #md5_before = md5(open(img_befor_cut_path, \"rb\").read())\n",
    "    #md5_after = md5(open(img_after_cut_path, \"rb\").read())\n",
    "    #if md5_before.hexdigest() != md5_after.hexdigest():\n",
    "    if same_rate > 0.9:\n",
    "        return True, ping_lun_list\n",
    "    return False, ping_lun_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def has_img_change(img_befor_cut_path):\n",
    "    global g_img_count\n",
    "    # 保存截图\n",
    "    img_after_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"now\" + \".png\"\n",
    "    pyautogui.screenshot(img_after_cut_path, region=(LEI_DIAN_FW_LEFT, LEI_DIAN_FW_TOP + LEI_DIAN_FW_TOP_BANNER, LEI_DIAN_FW_WIDTH - LEI_DIAN_FW_RIGHT_BANNER, LEI_DIAN_FW_HEIGHT - LEI_DIAN_FW_TOP_BANNER))\n",
    "    \n",
    "    #  像素相似比例比较 \n",
    "    image_before = Image.open(img_befor_cut_path)\n",
    "    image_after = Image.open(img_after_cut_path)\n",
    "    same_rate = compare(image_before, image_after)\n",
    "    \n",
    "    # 比较方式二：md5比较 \n",
    "    #md5_before = md5(open(img_befor_cut_path, \"rb\").read())\n",
    "    #md5_after = md5(open(img_after_cut_path, \"rb\").read())\n",
    "    #if md5_before.hexdigest() != md5_after.hexdigest():\n",
    "    if same_rate > 0.9:\n",
    "        print(\"   图片没有改变，same_rate:{}\".format(same_rate))\n",
    "        return False\n",
    "    return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 微信通知 \n",
    "def wei_xin_notify(str_in):\n",
    "    str_in = \"【jupyter自动化】\" + str_in\n",
    "    print(str_in)\n",
    "    pyautogui.moveTo(WEI_XIN_ICON_X, WEI_XIN_ICON_Y,duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(1)\n",
    "    pyperclip.copy(str_in)\n",
    "    time.sleep(1)\n",
    "    pyautogui.hotkey('Ctrl', 'v')\n",
    "    time.sleep(0.5)\n",
    "    pyautogui.press('enter') \n",
    "    time.sleep(1)\n",
    "    \n",
    "    pyautogui.moveTo(WEI_XIN_ICON_X, WEI_XIN_ICON_Y,duration=0.5)\n",
    "    pyautogui.click()\n",
    "    time.sleep(1)\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 看TikTok视频\n",
    "def look_tiktok_video():\n",
    "    global ping_lun_all_list\n",
    "    global DEVICE_LIST\n",
    "    \n",
    "    init()\n",
    "    g_i_test_count = 0\n",
    "    begin_time = time.time()\n",
    "    i_current_device_index = 0\n",
    "    while g_i_test_count < 2000:\n",
    "        g_i_test_count += 1\n",
    "\n",
    "        if g_i_test_count % 2 == 0:\n",
    "            past_time = time.time() - begin_time\n",
    "            print(\"已经完成了{}个视频,平均速度{}个/秒，{}秒/个\".format(g_i_test_count, g_i_test_count/past_time, past_time/g_i_test_count))\n",
    "        # 切换设备\n",
    "        click_location = DEVICE_LIST[i_current_device_index][\"click_loccation\"]\n",
    "        pyautogui.moveTo(click_location[0], click_location[1],duration=1)\n",
    "        pyautogui.click()\n",
    "        time.sleep(1)\n",
    "        i_current_device_index += 1\n",
    "        if i_current_device_index >= len(DEVICE_LIST):\n",
    "            i_current_device_index = 0\n",
    "        # 获得这个视频需要看完的时间：\n",
    "        I_NEED_LOOK_TIME = random.randint(int(20/len(DEVICE_LIST)), int(30/len(DEVICE_LIST)))\n",
    "            \n",
    "        # 向上滚屏\n",
    "        TRY_COUNT = 4\n",
    "        while True:\n",
    "            TRY_COUNT -= 1\n",
    "            if TRY_COUNT < 0:\n",
    "                wei_xin_notify(\"有一个手机画面没有变化，程序停止\")\n",
    "            assert TRY_COUNT >= 0\n",
    "            # 保存截图\n",
    "            img_befor_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"before\" + \".png\"\n",
    "            pyautogui.screenshot(img_befor_cut_path, region=(LEI_DIAN_FW_LEFT, LEI_DIAN_FW_TOP + LEI_DIAN_FW_TOP_BANNER, LEI_DIAN_FW_WIDTH - LEI_DIAN_FW_RIGHT_BANNER, LEI_DIAN_FW_HEIGHT - LEI_DIAN_FW_TOP_BANNER))\n",
    "            # 滑动的位置要随机 \n",
    "            print(LEI_DIAN_FW_LEFT + int(LEI_DIAN_FW_WIDTH/2) - 100)\n",
    "            print(LEI_DIAN_FW_LEFT + int(LEI_DIAN_FW_WIDTH/2) + 100)\n",
    "            i_slide_x = random.randint(LEI_DIAN_FW_LEFT + int(LEI_DIAN_FW_WIDTH/2) - 100, LEI_DIAN_FW_LEFT + int(LEI_DIAN_FW_WIDTH/2) + 100)\n",
    "            i_slide_y = random.randint(LEI_DIAN_FW_BOTTOM - DOU_YIN_SHI_PING_SLID_TOP - 100, LEI_DIAN_FW_BOTTOM - DOU_YIN_SHI_PING_SLID_TOP)\n",
    "            pyautogui.moveTo(i_slide_x, i_slide_y,duration=1)\n",
    "            i_slide_dist = random.randint(int(LEI_DIAN_FW_HEIGHT/2) - 250, int(LEI_DIAN_FW_HEIGHT/2) - 150)\n",
    "            pyautogui.dragTo(i_slide_x, i_slide_dist, duration=1)   \n",
    "            time.sleep(3)\n",
    "            bHasImgChange = has_img_change(img_befor_cut_path)\n",
    "            if bHasImgChange == True:\n",
    "                break\n",
    "            # 来一次返回键\n",
    "            pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + FAN_HUI_X, LEI_DIAN_FW_TOP + FAN_HUI_Y,duration=0.5)\n",
    "            pyautogui.click()\n",
    "            time.sleep(5)\n",
    "        \n",
    "        # 等待视频看完（等待的时间要随机）\n",
    "        while I_NEED_LOOK_TIME > 0:\n",
    "            I_NEED_LOOK_TIME -= 1\n",
    "            time.sleep(1)\n",
    "            # 中间随机对视频暂停一下\n",
    "            if random.randint(1, 30) == 5:\n",
    "                i_pause_x = random.randint(LEI_DIAN_FW_LEFT + int(LEI_DIAN_FW_WIDTH/2) - 100, LEI_DIAN_FW_LEFT + int(LEI_DIAN_FW_WIDTH/2) + 100)\n",
    "                i_pause_y = random.randint(LEI_DIAN_FW_BOTTOM - int(LEI_DIAN_FW_HEIGHT/2) - 100, LEI_DIAN_FW_BOTTOM - int(LEI_DIAN_FW_HEIGHT/2) + 100)\n",
    "                pyautogui.moveTo(i_pause_x, i_pause_y,duration=1)\n",
    "                pyautogui.click()\n",
    "                i_pause_time = random.randint(1, 8)\n",
    "                time.sleep(i_pause_time)\n",
    "                pyautogui.click()\n",
    "            #\"\"\"\n",
    "            # 中间随机进入个人主页面\n",
    "            if random.randint(1, 30) == 5:\n",
    "                pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + ZHU_YE_X, LEI_DIAN_FW_TOP + ZHU_YE_Y,duration=0.5)\n",
    "                pyautogui.click() \n",
    "                time.sleep(5)\n",
    "                # 随机决定是否要滑动查看\n",
    "                if random.randint(1, 5) == 5:\n",
    "                    i_slide_x = random.randint(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 - 100, LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + 100)\n",
    "                    i_slide_y = random.randint(LEI_DIAN_FW_BOTTOM - DOU_YIN_SHI_PING_SLID_TOP - 100, LEI_DIAN_FW_BOTTOM - DOU_YIN_SHI_PING_SLID_TOP)\n",
    "                    pyautogui.moveTo(i_slide_x, i_slide_y,duration=1)\n",
    "                    i_slide_dist = random.randint(LEI_DIAN_FW_HEIGHT/2 - 250, LEI_DIAN_FW_HEIGHT/2 - 150)\n",
    "                    pyautogui.dragTo(i_slide_x, i_slide_dist, duration=1)   \n",
    "                    time.sleep(0.1)\n",
    "                # 再次点击“+关注”按钮\n",
    "                #pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + 0, LEI_DIAN_FW_TOP + PING_LUN_Y - 130,duration=0.5)\n",
    "                #pyautogui.click() \n",
    "                #time.sleep(1)\n",
    "                #     返回键\n",
    "                pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + FAN_HUI_X, LEI_DIAN_FW_TOP + FAN_HUI_Y,duration=0.5)\n",
    "                pyautogui.click()\n",
    "                time.sleep(1)\n",
    "            #\"\"\"\n",
    "            # 中间随机点赞\n",
    "            if random.randint(1, 30) == 5:\n",
    "                pyautogui.moveTo(LEI_DIAN_FW_LEFT + int(LEI_DIAN_FW_WIDTH/2) + DIAN_ZAN_X, LEI_DIAN_FW_TOP + DIAN_ZAN_Y,duration=0.5)\n",
    "                pyautogui.click() \n",
    "                time.sleep(1)\n",
    "        \n",
    "        # 继续下一个视频\n",
    "        continue\n",
    "        \n",
    "    print(\"程序结束了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<Win32Window left=\"824\", top=\"1\", width=\"540\", height=\"728\", title=\"Meitu MP1709\">\n",
      "LEI_DIAN_FW_LEFT:824\n",
      "LEI_DIAN_FW_TOP:1\n",
      "LEI_DIAN_FW_BOTTOM:729\n",
      "Top banner保存到:./screenshot_img/top_banner.png\n",
      "OCR的结果： {'words_result_num': 2, 'words_result': [{'words': 'Meitu MP1709', 'location': {'height': 10, 'top': 10, 'width': 97, 'left': 8}}, {'words': '×+', 'location': {'height': 13, 'top': 10, 'width': 51, 'left': 189}}], 'log_id': 1602684483761392173}\n",
      "找到的远程设备有【1】个:[{'name': 'Meitu MP1709', 'click_loccation': (880, 16)}]\n",
      "994\n",
      "1194\n",
      "已经完成了2个视频,平均速度0.055658786525222735个/秒，17.966615200042725秒/个\n",
      "994\n",
      "1194\n",
      "994\n",
      "1194\n",
      "已经完成了4个视频,平均速度0.030057517455306326个/秒，33.26954734325409秒/个\n",
      "994\n",
      "1194\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-15-2f4d44a96b2c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mlook_tiktok_video\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-14-f39ec3055955>\u001b[0m in \u001b[0;36mlook_tiktok_video\u001b[1;34m()\u001b[0m\n\u001b[0;32m     55\u001b[0m         \u001b[1;32mwhile\u001b[0m \u001b[0mI_NEED_LOOK_TIME\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     56\u001b[0m             \u001b[0mI_NEED_LOOK_TIME\u001b[0m \u001b[1;33m-=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 57\u001b[1;33m             \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     58\u001b[0m             \u001b[1;31m# 中间随机对视频暂停一下\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     59\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mrandom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m30\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "look_tiktok_video()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 对TikTok视频关注、进主页、点赞、评论，并获得评论内容\n",
    "ping_lun_all_list = []\n",
    "def get_tiktok_ping_lun_and_ping_lun():\n",
    "    global ping_lun_all_list\n",
    "    init()\n",
    "    g_i_test_count = 0\n",
    "    begin_time = time.time()\n",
    "    while g_i_test_count < 200000:\n",
    "        g_i_test_count += 1\n",
    "\n",
    "        if g_i_test_count % 2 == 0:\n",
    "            past_time = time.time() - begin_time\n",
    "            print(\"已经完成了{}个视频,平均速度{}个/秒，{}秒/个\".format(g_i_test_count, g_i_test_count/past_time, past_time/g_i_test_count))\n",
    "           \n",
    "            \n",
    "        # 向上滚屏\n",
    "        TRY_COUNT = 2\n",
    "        while True:\n",
    "            TRY_COUNT -= 1\n",
    "            assert TRY_COUNT >= 0\n",
    "            # 保存截图\n",
    "            img_befor_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"before\" + \".png\"\n",
    "            pyautogui.screenshot(img_befor_cut_path, region=(LEI_DIAN_FW_LEFT, LEI_DIAN_FW_TOP + LEI_DIAN_FW_TOP_BANNER, LEI_DIAN_FW_WIDTH - LEI_DIAN_FW_RIGHT_BANNER, LEI_DIAN_FW_HEIGHT - LEI_DIAN_FW_TOP_BANNER))\n",
    "            pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2, LEI_DIAN_FW_BOTTOM - DOU_YIN_SHI_PING_SLID_TOP,duration=1)\n",
    "            pyautogui.dragTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2,LEI_DIAN_FW_HEIGHT/2 - 200, duration=1)   \n",
    "            time.sleep(0.1)\n",
    "            bHasImgChange = has_img_change(img_befor_cut_path)\n",
    "            if bHasImgChange == True:\n",
    "                break\n",
    "            time.sleep(10)\n",
    "        # chenyj test 只是看视频 \n",
    "        #\"\"\"\n",
    "        # 点击关注键\n",
    "        #pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + PING_LUN_X, LEI_DIAN_FW_TOP + PING_LUN_Y - 85,duration=0.5)\n",
    "        #pyautogui.click() \n",
    "        #time.sleep(1)\n",
    "        # 进入个人主页面 \n",
    "        pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + ZHU_YE_X, LEI_DIAN_FW_TOP + ZHU_YE_Y,duration=0.5)\n",
    "        pyautogui.click() \n",
    "        time.sleep(5)\n",
    "        # 再次点击“+关注”按钮\n",
    "        #pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + 0, LEI_DIAN_FW_TOP + PING_LUN_Y - 130,duration=0.5)\n",
    "        #pyautogui.click() \n",
    "        #time.sleep(1)\n",
    "        # 返回键\n",
    "        pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + FAN_HUI_X, LEI_DIAN_FW_TOP + FAN_HUI_Y,duration=0.5)\n",
    "        pyautogui.click()\n",
    "        time.sleep(1)\n",
    "        \"\"\"\n",
    "        \n",
    "        \"\"\"\n",
    "        # 按下点赞键\n",
    "        pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + DIAN_ZAN_X, LEI_DIAN_FW_TOP + DIAN_ZAN_Y,duration=0.5)\n",
    "        pyautogui.click() \n",
    "        time.sleep(1)\n",
    "        \n",
    "        # 按下抖音的评论键\n",
    "        # 保存截图\n",
    "        img_befor_cut_path = SCREENSHOT_SAVE_DIR + \"/\" + \"before\" + \".png\"\n",
    "        pyautogui.screenshot(img_befor_cut_path, region=(LEI_DIAN_FW_LEFT, LEI_DIAN_FW_TOP + LEI_DIAN_FW_TOP_BANNER, LEI_DIAN_FW_WIDTH - LEI_DIAN_FW_RIGHT_BANNER, LEI_DIAN_FW_HEIGHT - LEI_DIAN_FW_TOP_BANNER))\n",
    "        pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + PING_LUN_X, LEI_DIAN_FW_TOP + PING_LUN_Y,duration=0.5)\n",
    "        pyautogui.click()\n",
    "        time.sleep(1)\n",
    "        bHasImgChange = has_img_change(img_befor_cut_path)\n",
    "        if bHasImgChange == False:\n",
    "            print(\"发现一次无评论的视频，跳过\")\n",
    "            continue\n",
    "\n",
    "        # 滚动评论区直到结束\n",
    "        ping_lun_list = []\n",
    "        MAX_SLIDE_PING_LUN_COUNT = 2\n",
    "        while MAX_SLIDE_PING_LUN_COUNT > 0:\n",
    "            MAX_SLIDE_PING_LUN_COUNT -= 1\n",
    "            bSame, ping_lun_list_ = slide_ping_lun_then_get_and_wait_and_back()\n",
    "            ping_lun_list.extend(ping_lun_list_)\n",
    "            if True == bSame:\n",
    "                break\n",
    "        ping_lun_list.sort(key=lambda x: x[\"dian_zan_shu\"], reverse=True)\n",
    "        ping_lun_all_list.extend(ping_lun_list)\n",
    "        #print(\"得到的评论是{}\".format(ping_lun_list))\n",
    "        \n",
    "        # 发表评论\n",
    "        maybe_content_list = [\"太棒了\", \"666\", \"厉害\", \"这是哪里？\", \"不错\", \"哇塞\", \"可以可以\",\n",
    "                              \"( -'`-; )\", \"╥﹏╥...\", \"(。_。)\", \"（>○<）\",]\n",
    "        content = random.sample(maybe_content_list, 1)[0]\n",
    "        if len(ping_lun_list) >= 1:\n",
    "            content = ping_lun_list[0][\"ping_lun\"]\n",
    "        pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 - 40, LEI_DIAN_FW_TOP + 690,duration=0.5)\n",
    "        pyperclip.copy(content)\n",
    "        time.sleep(1)\n",
    "        pyautogui.click()\n",
    "        time.sleep(1)\n",
    "        pyautogui.hotkey('Ctrl', 'v')\n",
    "        time.sleep(0.5)\n",
    "        pyautogui.press('enter') \n",
    "        time.sleep(0.5)\n",
    "        \n",
    "        \n",
    "        # 按下返回键\n",
    "        pyautogui.moveTo(LEI_DIAN_FW_LEFT + LEI_DIAN_FW_WIDTH/2 + FAN_HUI_X, LEI_DIAN_FW_TOP + FAN_HUI_Y,duration=0.5)\n",
    "        pyautogui.click()\n",
    "        time.sleep(0.5)\n",
    "        #\"\"\"\n",
    "        \n",
    "        # 继续下一个视频\n",
    "        continue\n",
    "        \n",
    "    print(\"程序结束了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#get_tiktok_ping_lun_and_ping_lun()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## 把评论内容保存起来 \n",
    "FILE_PING_LUN_PATH = \"./repo_ping_lun.txt\"\n",
    "#   先加载过去的评论\n",
    "ping_lun_history_list = []\n",
    "if os.path.exists(FILE_PING_LUN_PATH):\n",
    "    with open(FILE_PING_LUN_PATH, \"r\", encoding=\"UTF-8\") as file:\n",
    "        for line in file.readlines():\n",
    "            line = line.strip()\n",
    "            if len(line) < 5:\n",
    "                continue\n",
    "            list_ = line.split(\"\\t\")\n",
    "            assert len(list_) == 2\n",
    "            ping_lun_history_list.append({\"ping_lun\":list_[0], \"dian_zan_shu\":int(list_[1])})\n",
    "    print(\"从文件 {}中共加载到{}条历史评论\".format(FILE_PING_LUN_PATH, len(ping_lun_history_list)))\n",
    "file_write = open(FILE_PING_LUN_PATH, \"a+\", encoding=\"UTF-8\")\n",
    "for ping_lun in ping_lun_all_list:\n",
    "    file_write.write(\"{}\\t{}\".format(ping_lun[\"ping_lun\"], ping_lun[\"dian_zan_shu\"]))\n",
    "    file_write.write(\"\\n\")\n",
    "file_write.close()\n",
    "print(\"将新增加的评论{}条保存到:{}\".format(len(ping_lun_all_list), FILE_PING_LUN_PATH))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
